package com.example.project.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.project.annotation.Log;
import com.example.project.core.controller.BaseController;
import com.example.project.core.domain.AjaxResult;
import com.example.project.core.page.TableDataInfo;
import com.example.project.entity.Journal;
import com.example.project.enums.BusinessType;
import com.example.project.service.JournalService;
import com.example.project.utils.poi.ExcelUtil;

/**
 * 问题变更历史主，记录Issue等对象的变更信息Controller
 * 
 * @author ruoyi
 * @date 2025-09-26
 */
@Controller
@RequestMapping("/system/journals")
public class JournalController extends BaseController {
	
	private String prefix = "system/journals";

	@Autowired
	private JournalService tJournalsService;

	@RequiresPermissions("system:journals:view")
	@GetMapping()
	public String journals() {
		return prefix + "/journals";
	}

	/**
	 * 查询问题变更历史主，记录Issue等对象的变更信息列表
	 */
	@RequiresPermissions("system:journals:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Journal tJournals) {
		startPage();
		List<Journal> list = tJournalsService.selectJournalsList(tJournals);
		return getDataTable(list);
	}

	/**
	 * 导出问题变更历史主，记录Issue等对象的变更信息列表
	 */
	@RequiresPermissions("system:journals:export")
	@Log(title = "问题变更历史主，记录Issue等对象的变更信息", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(Journal tJournals) {
		List<Journal> list = tJournalsService.selectJournalsList(tJournals);
		ExcelUtil<Journal> util = new ExcelUtil<Journal>(Journal.class);
		return util.exportExcel(list, "问题变更历史主，记录Issue等对象的变更信息数据");
	}

	/**
	 * 新增问题变更历史主，记录Issue等对象的变更信息
	 */
	@RequiresPermissions("system:journals:add")
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存问题变更历史主，记录Issue等对象的变更信息
	 */
	@RequiresPermissions("system:journals:add")
	@Log(title = "问题变更历史主，记录Issue等对象的变更信息", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Journal tJournals) {
		return toAjax(tJournalsService.insertJournals(tJournals));
	}

	/**
	 * 修改问题变更历史主，记录Issue等对象的变更信息
	 */
	@RequiresPermissions("system:journals:edit")
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		Journal tJournals = tJournalsService.selectJournalsById(id);
		mmap.put("tJournals", tJournals);
		return prefix + "/edit";
	}

	/**
	 * 修改保存问题变更历史主，记录Issue等对象的变更信息
	 */
	@RequiresPermissions("system:journals:edit")
	@Log(title = "问题变更历史主，记录Issue等对象的变更信息", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Journal tJournals) {
		return toAjax(tJournalsService.updateJournals(tJournals));
	}

	/**
	 * 删除问题变更历史主，记录Issue等对象的变更信息
	 */
	@RequiresPermissions("system:journals:remove")
	@Log(title = "问题变更历史主，记录Issue等对象的变更信息", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(tJournalsService.deleteJournalsByIds(ids));
	}
}
